<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--部门数据-->
      <el-col :span="4" :xs="24">
        <fileTrees @handleNodeClick="onTreeClick" :tableHeight="treeHeight" :isnoClick="isnoClick" :menuId="menuId">
        </fileTrees>
      </el-col>
      <!--离线接收数据-->
      <el-col :span="20" :xs="24" v-show="isShow">
        <queryCriteriaList v-if="listFrom.length > 0" :showSearch="showSearch" :listFrom="listFrom"
          @resetQuery="resetQuery" @handleQuery="handleQuery" ref="queryForm"></queryCriteriaList>
        <el-row :gutter="10" class="mb8" ref="refbut">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-takeaway-box" v-show="subStr == categoryType"
              v-hasPermi="['archive:szh:jieshouDa']" @click="handleJieshouTap()">接收</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-plus" v-show="subStr == categoryType && (subStr == 'F')"
              v-hasPermi="['archive:szh:addYqdaDa']" @click="handledeitTap(0)">著录</el-button>
            <el-button type="primary" plain icon="el-icon-plus" v-show="subStr == categoryType && (subStr == 'V')"
              v-hasPermi="['archive:szh:addFolderDa']" @click="handledeitTap(0)">著录</el-button>
            <el-button type="primary" plain icon="el-icon-plus" v-show="subStr == categoryType && (subStr == 'X')"
              v-hasPermi="['archive:szh:addItem']" @click="handledeitTap(0)">项目著录</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain icon="el-icon-edit" v-show="(subStr == 'F')"
              v-hasPermi="['archive:szh:updateYqdaDa']" @click="handledeitTap(1)">修改</el-button>
            <el-button type="success" plain icon="el-icon-edit" v-show="(subStr == 'V')"
              v-hasPermi="['archive:szh:updateFolderDa']" @click="handledeitTap(1)">修改</el-button>
            <el-button type="success" plain icon="el-icon-edit" v-show="(subStr == 'X')"
              v-hasPermi="['archive:szh:updateItemDa']" @click="handledeitTap(1)">修改</el-button>

          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain icon="el-icon-delete" v-hasPermi="['archive:wjzl:delete']"
              @click="handleDeleteTap()">删除</el-button>
          </el-col>
          <!-- <el-col :span="1.5">
            <el-button type="info" plain icon="el-icon-upload2"
              v-show="subStr == categoryType && (subStr == 'F' || subStr == 'X')" v-hasPermi="['archive:szh:showDR']"
              @click="handleImport">导入</el-button>
            <el-button type="info" plain icon="el-icon-upload2"
              v-show="subStr == categoryType && (subStr == 'X' || subStr == 'V')" v-hasPermi="['archive:szh:showVDR']"
              @click="handleImportFolder">案卷导入</el-button>
          </el-col>-->
          <el-col :span="1.5"> 
            <el-col :span="1.5">
            <el-button type="info" plain icon="el-icon-upload2"  v-show="subStr == categoryType && (subStr == 'F' || subStr == 'X')" v-hasPermi="['archive:szh:showDR']"
                        @click="handleImport">excel导入</el-button>
            <el-button type="info" plain icon="el-icon-upload2"  v-show="subStr == categoryType && (subStr == 'X' || subStr == 'V')" v-hasPermi="['archive:szh:showVDR']"
                        @click="handleImportFolder">excel案卷导入</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="info" plain icon="el-icon-upload2"  v-show="subStr == categoryType && (subStr == 'F' || subStr == 'X')" v-hasPermi="['archive:szh:showDR']"
                       @click="xmltxtImport('xml')">xml导入</el-button>
            <el-button type="info" plain icon="el-icon-upload2"  v-show="subStr == categoryType && (subStr == 'X' || subStr == 'V')" v-hasPermi="['archive:szh:showVDR']"
                       @click="xmltxtImportFolder('xml')">xml案卷导入</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="info" plain icon="el-icon-upload2"  v-show="subStr == categoryType && (subStr == 'F' || subStr == 'X')" v-hasPermi="['archive:szh:showDR']"
                       @click="xmltxtImport('txt')">txt导入</el-button>
            <el-button type="info" plain icon="el-icon-upload2"  v-show="subStr == categoryType && (subStr == 'X' || subStr == 'V')" v-hasPermi="['archive:szh:showVDR']"
                       @click="xmltxtImportFolder('txt')">txt案卷导入</el-button>
          </el-col>
            <!--            <el-button type="warning" plain icon="el-icon-printer"  @click="printTap">目录打印</el-button>-->

            <el-button type="warning" plain icon="el-icon-printer" v-hasPermi="['archive:szh:showMLDY']"
              @click="print1Tap">目录打印</el-button>
          </el-col>

          <!-- <el-col :span="1.5" v-show="subStr == 'V'">
            <el-button type="primary" plain icon="el-icon-printer" v-hasPermi="['archive:szh:showFDR']"
              @click="handleImportFile()">卷内件导入</el-button>
          </el-col> -->
          <el-col :span="1.5" v-show="subStr == 'V'">
            <el-button type="primary" plain icon="el-icon-printer" v-hasPermi="['archive:szh:showFDR']"
                       @click="handleImportFile()">excel卷内件导入</el-button>
          </el-col>
            <el-col :span="1.5" v-show="subStr == 'V'">
                <el-button type="primary" plain icon="el-icon-printer" v-hasPermi="['archive:szh:showFDR']"
                           @click="xmltxtImportFile('xml')">xml卷内件导入</el-button>
            </el-col>
            <el-col :span="1.5" v-show="subStr == 'V'">
                <el-button type="primary" plain icon="el-icon-printer" v-hasPermi="['archive:szh:showFDR']"
                           @click="xmltxtImportFile('txt')">txt卷内件导入</el-button>
            </el-col>


          <el-col :span="1.5" v-show="subStr == 'X'">
            <el-button type="primary" plain icon="el-icon-printer" v-hasPermi="['archive:szh:addFolderDa1']"
              @click="handledeitanJuanTap()">案卷著录</el-button>
          </el-col>

          <el-col :span="1.5" v-show="subStr == 'X'">
            <el-button type="primary" plain icon="el-icon-printer" v-hasPermi="['archive:szh:updateFolderDa1']"
              @click="handledeitanDeitJuanTap()">案卷修改</el-button>
          </el-col>

          <el-col :span="1.5" v-show="subStr == 'V' || subStr == 'F'">
            <el-button type="primary" icon="el-icon-files" v-hasPermi="['archive:wjzl:pieceNumber1']"
              @click="rowNumber">{{ subStr == 'F' ? '排件号' : '排卷号'
              }}</el-button>
          </el-col>
          <el-col :span="1.5" v-show="subStr == 'V' || subStr == 'F'">
            <el-button type="primary" icon="el-icon-files" v-hasPermi="['archive:wjzl:clearNumber1']" @click="cleanUp">{{
              subStr == 'F' ? '清空件号' : '清空卷号'
            }}</el-button>
          </el-col>
          <el-col :span="1.5" v-show="subStr == 'V' || subStr == 'F'">
            <el-button type="primary" icon="el-icon-files" v-hasPermi="['archive:wjzl:insertPieceNumber3']"
              @click="manualNumber">{{ subStr == 'F' ? '手动排件号' : '手动排卷号'
              }}</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-takeaway-box" v-show="subStr == categoryType"
              v-hasPermi="['archive:szh:jieshouDa']" @click="handleSXJCTap()">四性检测</el-button>
          </el-col>
          <!--          <el-col :span="1.5" v-if="subStr == 'V' && subStr == categoryType">-->
          <!--            <el-button type="warning" plain icon="el-icon-document"-->
          <!--                      @click="handleInfoDetailTap()">案卡信息</el-button>-->
          <!--          </el-col>-->
          <right-toolbar :showSearch.sync="showSearch" @queryTable="queryTableTap"></right-toolbar>
        </el-row>
        <tableList v-if="tableHeight" :tableHeaderList="tableHeaderList" @handleSelectionChange="handleSelectionChange"
          :tableData="tableData" :loading="loading" :tableHeight="tableHeight" @celldblclick="celldblclick"
          @sortChange="sortChange" ref="ref"></tableList>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
          @pagination="getlistPost" />
      </el-col>

      <el-col :span="20" :xs="24" v-show="!isShow" class="empty">
        <el-empty :image-size="200"></el-empty>
      </el-col>

    </el-row>
    <!-- start 组件著录、修改 -->
    <jiandeit v-if="jianOpen" :open="jianOpen" :openInfo="openInfo" @closeDelDialog="closeDelDialog"
      @submitDetail="submitDetail" :isParams="2">
    </jiandeit>
    <!-- end  组件著录、修改-->

    <!-- start 组卷著录、修改 -->
    <juandeit v-if="juanOpen" :open="juanOpen" :openInfo="openInfo" @closeDelDialog="closeDelDialog"
      @submitDetail="submitDetail" :isParams="2" :isShow="false"></juandeit>
    <!-- end  组卷著录、修改-->

    <!-- start 项目著录  修改 -->
    <projectdeit v-if="projectOpen" :open="projectOpen" :openInfo="openInfo" @submitDetail="submitDetail"
      @closeDelDialog="closeDelDialog" :isParams="2"></projectdeit>
    <!-- end 项目著录、修改 -->

    <!--start  组件详情 -->
    <jianDetailsOpen v-if="jianDetailsOpen" :open="jianDetailsOpen" :celldbData="celldbData"
      @detailsHandleClose="detailsHandleClose">
    </jianDetailsOpen>
    <!--end 组件详情 -->
    <!-- start 组卷\项目详情 -->
    <juanDetailsOpen v-if="juanDetailsOpen" :open="juanDetailsOpen" :celldbData="celldbData"
      @detailsHandleClose="detailsHandleClose"></juanDetailsOpen>
    <!-- end 组卷\项目详情 -->

    <!-- start 项目下面的卷列表修改 -->
    <projectJuanlistDeit v-if="projectJuanlistDeitOpen" :open="projectJuanlistDeitOpen" :celldbData="celldbData"
      @detailsHandleClose="detailsHandleClose" :openInfo="openInfo" :isParams="2" :isShow="false"></projectJuanlistDeit>
    <!-- end  项目下面的卷列表修改 -->

     <!-- 用户导入excel对话框 -->
     <dataImport :upload="upload" @uploadCancel="uploadCancelTap" @importTemplate="importTemplateTap" @uploadFile="uploadFile" :isShowTooltip="isShowTooltip" @submitFileForm="submit" :importType="importType"></dataImport>

<!-- 导入匹配页 -->
<importMatch :match="match" ref="matchRef" @matchCancel="matchCancelTap" @submitMatch="submitMatch"></importMatch>



    <!-- start  目录打印 -->
    <vPrint v-if="printOpen" :open="printOpen" @closeDelDialog="closeDelDialog" :tableHeaderList="tableHeaderList"
      :printList="printList"></vPrint>
    <!-- end  目录打印 -->

    <!-- 手动排档号 -->
    <manualNumber :number="number" @numberCancel="numberCancelTap" @submitNumberForm="submitNumberForm"></manualNumber>

    <!-- 案卡信息 -->
    <InformationDetail :info="info" @infoCancelTap="infoCancelTap" ref="infoRef"></InformationDetail>
    <!-- start  检测方案弹窗 -->
    <el-dialog title="请选择检测方案" :visible.sync="dialogVisible" width="20%" :before-close="handlecloseDelDialog"
      :close-on-click-modal="false">
      <el-select v-model="sxjcType" placeholder="请选择" style="width:100%">
        <el-option v-for="item in sxjcList" :key="item.identification" :label="item.identification"
          :value="item.identification">
        </el-option>
      </el-select>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleYes">确 定</el-button>
      </span>
    </el-dialog>
    <!-- end  检测方案弹窗-->

    <!-- 导出返回日志列表 -->
    <el-dialog title="标题" :visible.sync="dialogVisibleLog" width="40%" :before-close="handlecloseDelDialog"
      :close-on-click-modal="false">
      <el-card class="box-card" style="height:400px;overflow-y: scroll;">
      <div v-for="(item,index) in logList" :key="index" class="text item">
        {{index+1}}:{{item}}
      </div>
    </el-card>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handlecloseDelDialog">确 定</el-button>
        <el-button type="primary" @click="handleLogYes">下载</el-button>
      </span>
    </el-dialog>
    <!--end 导出返回日志列表 -->
  </div>
</template>
<script>
import {
  getqueryfieldList,
  getlistbytreenodeList,
  getthbytreenodeHeaderList,
  deleteData,
  jieshou, pieceNumber1, clearNumber1, getLastZlx3, insertPieceNumber, handoverDetection,jieshouSzhDa
} from "@/api/archive/digitalizeReceive/archiveReception.js";
import queryCriteriaList from "@/components/queryCriteriaList/index.vue"  //查询列表
import fileTrees from "@/components/fileTrees/index.vue"  //档案树
import { getGroupTree } from "@/api/archive/archivesCategory.js"
import tableList from "@/components/tableList/index.vue"
import jiandeit from "@/views/archive/fileCollection/offlinReception/jiandeit.vue" //件添加修改弹窗
import juandeit from "@/views/archive/fileCollection/offlinReception/juandeit.vue" //卷添加修改弹窗
import projectdeit from "@/views/archive/fileCollection/offlinReception/projectdeit.vue" //卷添加修改弹窗
import projectJuanlistDeit from "@/views/archive/fileCollection/offlinReception/projectJuanlistDeit.vue" //项目下面的卷列表修改
import treeHeight from '@/mixins/treeHeight'//计算左侧树的高度
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue' //卷详情
import dataImport from "@/components/dataImportComponent/dataImport.vue";
import importMatch from "@/components/dataImportComponent/importMatch.vue";
import vPrint from "@/components/printComponent/index.vue" //目录打印弹窗模板
import ManualNumber from "@/views/archive/digitalizeReceive/archiveReception/manualNumber";
import { getLastIndexOf } from "@/utils/index.js"
import { geturl, getTitle,uploadList,uploadXml,uploadTxt  } from "@/api/archive/fileCollection/offlinReception";
import InformationDetail from "@/views/archive/digitalizeReceive/archiveReception/informationDetail";
import { getTypeObject } from "@/api/archive/dict/dictManageData";
import { getdetectionSchemeList } from '@/api/archive/archiveTransfer/archiveTransfer.js'
export default {
  mixins: [treeHeight], // 混入方法
  components: {
    InformationDetail,
    ManualNumber,
    queryCriteriaList,
    fileTrees,
    jiandeit,
    juandeit,
    tableList,
    projectdeit,
    jianDetailsOpen,
    juanDetailsOpen,
    dataImport,
    importMatch,
    vPrint,
    projectJuanlistDeit
  },
  data() {
    return {
      menuId: '',
      isnoClick: true,
      scroll: "",
      loading: false,
      // 显示搜索条件
      showSearch: true,
      listFrom: [], //查询框列表
      isShow: false, //是否显示右侧数据
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      tableHeaderList: [], //table表头数据
      tableData: [],//table列表数据
      jianOpen: false, //组件打开关闭
      juanOpen: false, //组卷打开关闭
      projectOpen: false,//项目打开关闭
      jianDetailsOpen: false,//件详情弹窗
      juanDetailsOpen: false,//卷详情弹窗
      projectJuanlistDeitOpen: false,//项目下面的卷列表修改
      openInfo: { //件 卷  项目
        opens: false,
        categoryId: undefined,
        menuId: undefined,
        type: undefined
      },
      tableHeight: "",
      ids: undefined,
      single: "",
      multiple: true,
      selection: [],
      rowList: "", //当前点击的数据
      treeRowData: "", //点击档案树显示当前点击数据
      subStr: "",  //获取点击当前树的 件 卷  项目 截取 sub_table_name显示
      printOpen: false, //打印弹出传
      printList: [],
      responselist: "",//门类详情
     // 用户导入参数
     upload: {
                // 是否显示弹出层（用户导入）
                open: false,
                // 弹出层标题（用户导入）
                title: "",
            },
            // 导入文件类型  件、卷、项目
            uploadType: null,
            // 表格表头
            xlsTitle: [],
            // 可导入项
            sysTitle: [],
            // 匹配参数
            match: {
                // 是否显示弹出层
                open: false,
                // 弹出层标题
                title: "",
            },
      file: null,
      // 手动排档号
      number: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: ""
      },

      categoryType: "",
      HierarchyType: "", //层级类型

      // 案卡信息
      info: {
        // 是否显示弹出层
        open: false,
      },
      dictList: [],
      sxjcList: [],//四性检测方案列表数据
      sxjcType: undefined,
      dialogVisible: false, //检测方案弹窗
      dialogVisibleLog:false, //日志弹窗
      logList:[],
      importType:undefined,  //控制上传类型
      isShowTooltip:undefined, //上传是否有下载模版
      typeButtonPost:undefined //判断导入接口
    }
  },

  created() {
    this.menuId = this.$route.meta.menuId
  },


  methods: {
    /**四性检测方案列表 */
    getdetectionSchemeListPOST() {
      getdetectionSchemeList({
        state: "1",
        phase: "1",
        categoryId: this.queryParams.categoryId,
        // menuType: this.menuType,
        // daType: this.daType,
      }).then(res => {
        if (res.rows.length > 0) {
          this.sxjcList = res.rows
          this.dialogVisible = true;
        } else {
          this.$message({ message: '当前门类数据还没有四性检测方案数据', type: 'warning' })
        }
      })
    },
    handlecloseDelDialog() {
      this.sxjcType = undefined
      this.dialogVisible = false
      this.dialogVisibleLog=false
    },
    handleSXJCTap() {
      if (!this.multiple) {
        this.dialogVisible = true;
        this.getdetectionSchemeListPOST();
      } else {
        this.$message({ message: '请选择要检测的数据哦', type: 'warning' })
      }
    },

    //选择检测方案
    handleYes() {
      if (this.sxjcType == undefined) {
        this.$message({ message: '请选择方案', type: 'warning' })
        return false
      }
      if (this.subStr == 'X') {
        this.daType = 3
      } else if (this.subStr == 'V') {
        this.daType = 1
      } else if (this.subStr == 'F') {
        this.daType = 0
      }
      var dataArr = {
        "categoryId": this.queryParams.categoryId,
        "link": "1",
        "code": this.sxjcType,
        "daIds": this.ids,
        // "menuType": this.menuType,
        "daType": this.daType
      }
      this.$modal.loading("正在检测中...");
      this.dialogVisible = false;
      handoverDetection(dataArr).then(res => {
        if (res.code == "200") {
          if (res.data.daId.length > 0) {
            this.$message({ message: '检测已完成,有' + res.data.daId.length + '条不通过', type: 'success' })
          } else {
            this.$message({ message: '检测已完成', type: 'success' })
          }
          this.sxjcType = undefined;
          this.getlistHeaderPost();
          this.$modal.closeLoading();
        }
      }).catch(res => {
        this.sxjcType = undefined;
        this.getlistHeaderPost();
        this.$modal.closeLoading();
      })


    },
    //动态设置table的高度
    tableHeightData() {
      this.$nextTick(
        () => {
          let h = document.documentElement.clientHeight
          h = h - 200
          if (this.$refs.queryForm) { // 页面上如果有面包屑区域徐减去它的高度
            h = h - this.$refs.queryForm.$el.offsetHeight
          }

          if (this.$refs.refbut) { // 页面上如果有分页区域徐减去它的高度
            h = h - this.$refs.refbut.$el.offsetHeight
          }
          this.tableHeight = h > 310 ? h : 310 // 根据自己项目定高度
          return h
        }
      )
    },

    // 树节点单击事件
    onTreeClick(data) {
      this.isnoClick = false;
      this.treeRowData = data;
      if (data.categoryId != null) {
        this.isShow = true
      } else {
        this.isShow = false
      }
      if (this.$refs.queryForm != undefined) {
        this.$refs.queryForm.queryParams = {};
      }
      if (data.nodeType == null || data.nodeType == "t" || data.nodeType == "f") {
        this.isnoClick = true;
        return false;
      }
      this.HierarchyType = data.nodeType
      this.loading = true;
      this.queryParams = data;
      this.queryParams.state = 3;
      this.queryParams.jsType = 2;
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      this.queryParams.order = '';
      if (this.queryParams.sub_table_name != undefined) {
        this.subStr = getLastIndexOf(this.queryParams.sub_table_name);
        let stb = this.queryParams.sub_table_name;
        let stbArr = stb.split("_");
        if (stbArr[stbArr.length - 3] == 0) {
          this.categoryType = 'F'
        } else if (stbArr[stbArr.length - 3] == 1) {
          this.categoryType = 'V'
        } else if (stbArr[stbArr.length - 3] == 3) {
          this.categoryType = 'X';
        }
      } else {
        this.getGroupTreePost(data.categoryId);
      }
      this.getqueryfieldListPost();//点击树节点获取查询字段
      this.getlistHeaderPost();/**点击树节点,获取table表头数据 */
      if (this.$refs.ref != undefined) {
        this.$refs.ref.clearSort()
      }
    },
    // 获取字符串中最后一个_前面的内容和获取最后一个"_"之后的内容
    getLastIndexOf(sub_table_name) {
      // 获取字符串中最后一个_前面的内容:
      var str = sub_table_name;
      var index = str.lastIndexOf("_");
      var strData = str.substring(0, index);
      //获取最后一个"_"之后的内容
      var index1 = strData.lastIndexOf("_");
      strData = strData.substring(index1 + 1, strData.length);
      return strData;

    },

    //档案门类树门类根据categoryID回显
    getGroupTreePost(ID) {
      getGroupTree(ID).then(response => {
        this.responselist = response.data;
        if (response.data.type == "0") { //件
          this.queryParams.sub_table_name = response.data.fileTableName;
        } else if (response.data.type == "1") { //卷
          this.queryParams.sub_table_name = response.data.folderTableName;
        } else { //项目
          this.queryParams.sub_table_name = response.data.itemTableName;
        }
        this.subStr = getLastIndexOf(this.queryParams.sub_table_name);
        let stb = this.queryParams.sub_table_name;
        let stbArr = stb.split("_");
        if (stbArr[stbArr.length - 3] == 0) {
          this.categoryType = 'F'
        } else if (stbArr[stbArr.length - 3] == 1) {
          this.categoryType = 'V'
        } else if (stbArr[stbArr.length - 3] == 3) {
          this.categoryType = 'X';
        }
      });
    },

    /** 点击树节点获取查询字段 */
    getqueryfieldListPost(data) {
      this.queryParams.searchcolumn = undefined
      this.listFrom = []
      getqueryfieldList({
        categoryId: this.queryParams.categoryId,
        menuId: this.queryParams.menuId,
        subTableName: this.queryParams.sub_table_name,

      }).then(response => {
        this.listFrom = response.rows;
      });
    },
    /**点击树节点,获取table表头数据 */
    getlistHeaderPost() {
      // this.queryParams.searchcolumn = undefined
      getthbytreenodeHeaderList({
        categoryId: this.queryParams.categoryId, menuId: this.queryParams.menuId, subTableName: this.queryParams.sub_table_name
      }
      ).then(response => {
        this.tableHeaderList = response.rows;
        var fields = []
        for (var i in response.rows) {
          fields.push(response.rows[i].FIELD_NAME)
        }
        this.queryParams.fields = fields.toString()

        //获取指定字典列表
        var headerlist = [];
        for (var i = 0; i < this.tableHeaderList.length; i++) {
          if (this.tableHeaderList[i].SHOWTYPE.toString().indexOf('5') != -1) {
            this.tableHeaderList[i].SHOWTYPE = 5
          }
          if (this.tableHeaderList[i].SHOWTYPE == 5) {
            // console.log(this.tableHeaderList[i])
            headerlist.push(this.tableHeaderList[i].FIELD_NAME)
          }
        }
        // console.log(headerlist,"++++")
        if (headerlist.length > 0) {
          getTypeObject(headerlist).then((res) => {
            this.dictList = res.data;
          })
        }
        this.getlistPost();
        this.isnoClick = true;
      });
    },
    /** 点击树节点,获取table数据*/
    getlistPost() {
      if (this.queryParams.fields==''){
        this.$message({ message: '请先对该门类进行配置！', type: 'warning' })
        return ;
      }
      getlistbytreenodeList(this.queryParams).then(response => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
        this.tableHeightData();
        // this.isnoClick = true;
      });
    },

    //是否选择数据
    handleSelectionChange(ids, single, multiple, selection) {
      this.ids = ids.toString();
      this.single = single;
      this.multiple = multiple;
      this.selection = selection;
    },

    //表单重置
    resetQuery() {
      this.queryParams.searchcolumn = undefined
      this.queryParams.order = undefined;
      this.$refs.ref.clearSort()
      this.getlistPost();
    },
    //点击搜索
    handleQuery(searchcolumn) {
      var column = searchcolumn.filter(item => { return item.value !== '' && item.value !== null })
      this.queryParams.searchcolumn = column
      this.queryParams.order = undefined;
      this.$refs.ref.clearSort()
      this.getlistPost();
    },
    //刷新页面
    queryTableTap() {
      this.queryParams.order = undefined;
      this.getlistPost();
      this.$refs.ref.clearSort()
    },

    //件  this.jianOpen  著录和修改     //组卷 this.juanOpen 著录和修改    //项目 this.projectdOpen 著录和修改
    handledeitTap(e) {
      this.openInfo = {
        opens: true,
        categoryId: this.queryParams.categoryId,
        menuId: this.queryParams.menuId,
        folderId: undefined, //组卷id
        itemId: undefined, //项目Id
        subTableName: this.queryParams.sub_table_name,
        nodeType: this.queryParams.nodeType,
        parentNodeType: this.queryParams.parentNodeType,
        parentSubTableName: this.queryParams.parentSubTableName,
        subStr: this.subStr,
      }

      if (e == 1) {  //修改
        if (this.ids == undefined) {
          this.$message({ message: '请选择要修改的数据哦', type: 'warning' })
          return false
        }
        if (this.single) {
          this.$message({ message: '请选择一条要修改的数据哦', type: 'warning' })
          return false
        }

        this.openInfo.ids = this.ids; //组件Id;
      } else { //添加
        this.openInfo.ids = undefined
      }
      if (this.subStr == "F") {  //F 件
        this.openInfo.type = 0
        this.jianOpen = true
      } else if (this.subStr == "V") { //卷
        this.openInfo.type = 1
        this.juanOpen = true;
      } else { //项目
        this.openInfo.type = 3
        this.projectOpen = true;
      }

    },

 // 导入按钮  组件/项目
 handleImport() {
      this.importType="xls、xlsx"
      this.isShowTooltip=true
      if (this.subStr == "F") {
        // console.log("件导入")
        this.upload.title = "件数据";
        this.upload.open = true;
        this.uploadType = 0
      } else {
        // console.log("项目导入")
        this.upload.title = "项目数据";
        this.upload.open = true;
        this.uploadType = 3
      }
    },
    // 案卷导入
    handleImportFolder() {
      this.importType='xls、xlsx'
      this.isShowTooltip=true
      if(this.subStr == 'X') {
        if (this.ids == undefined) {
          this.$message({message: '请先选择数据哦', type: 'warning'})
          return false
        }
        if (this.single) {
          this.$message({message: '请选择一条数据哦', type: 'warning'})
          return false
        }
      }
      // console.log("案卷导入")
      this.upload.title = "案卷数据";
      this.upload.open = true;
      this.uploadType = 1
    },
    //给组卷 卷内件导入
    handleImportFile(){
        this.importType='xls、xlsx'
        this.isShowTooltip=true
      this.upload.title = "卷内件数据";
      this.upload.open = true;
      this.uploadType = 0
    },
    // 导入按钮  xml/txt组件/项目
    xmltxtImport(val) {
      this.importType=val
      this.isShowTooltip=false
      this.typeButtonPost=1
      if (this.subStr == "F") {
        // console.log("件导入")
        this.upload.title = "卷内件数据"+val;
          if(this.categoryType=="F"){
              this.upload.title = "件数据"+val;
          }
        this.upload.open = true;
        this.uploadType = 0
      } else {
        // console.log("项目导入")
        this.upload.title = "项目数据"+val;
        this.upload.open = true;
        this.uploadType = 3
      }
    },

    // xml/txt案卷导入
    xmltxtImportFolder(val) {
      this.importType=val;
      this.isShowTooltip=false
      this.typeButtonPost=1
      if(this.subStr == 'X') {
        if (this.ids == undefined) {
          this.$message({message: '请先选择数据哦', type: 'warning'})
          return false
        }
        if (this.single) {
          this.$message({message: '请选择一条数据哦', type: 'warning'})
          return false
        }
      }
      // console.log("案卷导入")
      this.upload.title = "案卷数据"+val;
      this.upload.open = true;
      this.uploadType = 1
    },
      //给组卷 卷内件导入
      xmltxtImportFile(val){
          this.importType=val;
          this.isShowTooltip=false
          this.typeButtonPost=1
          this.upload.title = "卷内件数据";
          this.upload.open = true;
          this.uploadType = 0
      },

    // 关闭导入  /件/卷/项目
    uploadCancelTap() {
      this.upload.open= false;
      this.getlistHeaderPost();
    },
    // 下载模板
    importTemplateTap() {
      this.form = {
        type: this.uploadType,
        categoryId: this.queryParams.categoryId
      }
      if(this.uploadType == 0) {
        // console.log("卷内件下载模板")
        this.download('/archive/daImport/download?type='+this.uploadType+"&categoryId="+this.queryParams.categoryId+"&menuId="+ this.menuId, {
        }, `fileData_template_${new Date().getTime()}.xlsx`)
      } else if(this.uploadType == 1) {
        // console.log("案卷下载模板")
        this.download('/archive/daImport/download?type='+this.uploadType+"&categoryId="+this.queryParams.categoryId+"&menuId="+ this.menuId, {
        }, `folderData_template_${new Date().getTime()}.xlsx`)
      } else {
        // console.log("项目下载模板")
        this.download('/archive/daImport/download?type='+this.uploadType+"&categoryId="+this.queryParams.categoryId+"&menuId="+ this.menuId, {
        }, `itemData_template_${new Date().getTime()}.xlsx`)
      }
    },
    // 上传文件
    uploadFile(concent) {
      this.file = concent.file
      if(this.isShowTooltip){
        const formData = new FormData();
        formData.append("file", concent.file);
        formData.append("categoryId", this.queryParams.categoryId);
        formData.append("type", this.uploadType);
        getTitle(formData).then(response => {
          this.xlsTitle = response.data.xlsTitle.map(item =>{
            return {
              xlsNum: item.num,
              xlsName: item.name
            }
          })
          this.sysTitle = response.data.sysTitle.map(item => {
            return {
              name: item.fieldName,
              caption: item.fieldCaption,
              showType: item.showType,
              dataLength: item.dataLength,
              isNoEmpty: item.isNoEmpty,
              defaultValue: item.defaultValue,
              checkChongfu: item.checkChongfu,
              specialCharacter:item.specialCharacter
            }
          })
          this.$nextTick(() => {   //此函数执行时所有的DOM挂载和渲染都已完成
            this.$refs.matchRef.init(this.xlsTitle,this.sysTitle);     //获取子组件中init方法并将父组件数据传递给子组件
          });
        })
      }
    },
 
    // 点击确认val
    submit(val) {

if(this.isShowTooltip){
  this.upload.open = false
  if(this.uploadType == 0) {
    this.match.title = "卷内件导入"
  } else if(this.uploadType == 1) {
    this.match.title = "案卷导入"
  } else {
    this.match.title = "项目导入"
  }
  this.match.open = true
  // this.$nextTick(() => {   //此函数执行时所有的DOM挂载和渲染都已完成
  //   this.$refs.matchRef.init(this.xlsTitle,this.sysTitle);     //获取子组件中init方法并将父组件数据传递给子组件
  // });
}else{
  //不弹匹配字段框
  if(this.typeButtonPost==1){
    const formData = new FormData();
    formData.append("file", this.file);
    formData.append("id", this.queryParams.categoryId);
    formData.append("type", this.uploadType == 0 ? 'f' : 'v');
    if (this.importType == 'xml') {
      uploadXml(formData,this.queryParams.categoryId,this.uploadType == 0 ? 'f' : 'v').then(response => {
        this.$modal.msgSuccess(response.msg);
        this.upload.open= false;
        this.getlistPost()
      })
    } else if (this.importType == 'txt'){
      uploadTxt(formData,this.queryParams.categoryId,this.uploadType == 0 ? 'f' : 'v').then(response => {
        this.$modal.msgSuccess(response.msg);
        this.upload.open= false;
        this.getlistPost()
      })
    }
  }
}
},
    submitMatch(matchedData) {
      this.form = {
        categoryId: this.queryParams.categoryId,
        state: this.queryParams.state,
        jsType: this.queryParams.jsType,
        colNames: matchedData
      }
      // console.log(this.subStr, this.uploadType, this.ids)
      if(this.subStr == "F") {
        if(this.uploadType == 0) {
          this.form.type = this.uploadType
          // this.form.folderId = "-1"
        } else {
          this.form.type = this.uploadType
        }
      } else if(this.subStr == "V") {
        if(this.uploadType == 0){
          this.form.type = 0
          if(this.ids == undefined || this.ids == null || this.ids == '') {
            this.form.folderId = "-1"
          } else {
            this.form.folderId = this.ids
          }
        } else {
          this.form.type = this.uploadType
        }
      } else {
        if(this.uploadType == 1){
          this.form.type = 1
          this.form.itemId = this.ids
        } else {
          this.form.type = this.uploadType
        }
      }
      const formData = new FormData();
      formData.append("file", this.file);
      formData.append("dataStr", JSON.stringify(this.form));
      uploadList(formData).then(response => {
        this.$modal.msgSuccess(response.msg);
        // this.match.open= false;
        this.getlistPost()
      })
      this.match.open= false;
    },
    matchCancelTap() {
      this.match.open= false;
    },

    exportText(dataStr) {
      const name = "导入日志"+new Date;
      const element = document.createElement('a')
      element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(dataStr))
      element.setAttribute('download', name)
      element.style.display = 'none'
      element.click()
    },
    handleLogYes(){
      var that=this;

      this.exportText(that.logList.join("\n"));
    },

    //给项目案卷著录
    handledeitanJuanTap() {
      this.openInfo = {
        opens: true,
        categoryId: this.queryParams.categoryId,
        menuId: this.queryParams.menuId,
        type: 1, //传卷类型  0,组件 1，组卷 3，项目
        folderId: undefined, //组卷id
        itemId: undefined, //项目Id
        subTableName: this.queryParams.sub_table_name
      }
      if (this.ids == undefined) {
        this.$message({ message: '请选择先选择数据哦', type: 'warning' })
        return false
      }
      if (this.single) {
        this.$message({ message: '请选择一条数据哦', type: 'warning' })
        return false
      }
      this.openInfo.itemId = this.ids; //项目Id;
      this.openInfo.button = 'dajsajzl' // 档案接收案卷著录
      this.juanOpen = true;
    },

    //修改项目下面的案卷
    handledeitanDeitJuanTap() {
      var that = this;
      if (this.ids == undefined) {
        this.$message({ message: '请选择先选择数据哦', type: 'warning' })
        return false
      }
      if (this.single) {
        this.$message({ message: '请选择一条数据哦', type: 'warning' })
        return false
      }
      var row = this.tableData.filter(item => { return this.ids == item.ID })
      var level = "";
      if (getLastIndexOf(this.queryParams.sub_table_name) == "F") {  //F 件
        level = 0
      } else if (getLastIndexOf(this.queryParams.sub_table_name) == "V") { //卷
        level = 1
      } else { //项目
        level = 3
      }
      this.openInfo = {
        opens: true,
        categoryId: this.queryParams.categoryId,
        menuId: this.queryParams.menuId,
        folderId: undefined, //组卷id
        itemId: undefined, //项目Id
        subTableName: this.responselist.fileTableName,
        nodeType: "l",
        subStr: "V",
        type: 1
      }
      this.celldbData = {
        id: row[0].ID,
        categoryId: this.queryParams.categoryId,
        menuId: this.queryParams.menuId,
        sub_table_name: this.queryParams.sub_table_name,
        label: row[0].XMMC,
        level: level,
        ifSub_table_name: this.queryParams.sub_table_name,
        isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
      }
      this.openInfo.button = 'dajsajxg'
      that.projectJuanlistDeitOpen = true
    },

    //关闭著录 \件\ 组卷
    closeDelDialog() {
      this.jianOpen = false //件
      this.juanOpen = false //卷
      this.projectOpen = false; //项目
      this.printOpen = false;//目录打印
      this.openInfo = ""
    },

    //著录成功
    submitDetail() {
      this.jianOpen = false;
      this.juanOpen = false //卷
      this.projectOpen = false; //项目
      this.getlistHeaderPost();
    },

    //删除
    handleDeleteTap() {
      if (this.ids != undefined && !this.multiple) {
        this.$modal.confirm('是否确认删除所选数据项？').then(function () {
        }).then(() => {
          let type = "";
          if (this.subStr == "F") {  //F 件
            type = 0;
          } else if (this.subStr == "V") { //卷
            type = 1;
          } else { //项目
            type = 3;
          }
          deleteData({
            type: type,
            //nodeType: this.queryParams.nodeType,
            categoryId: this.queryParams.categoryId,
            //sub_table_name: this.queryParams.sub_table_name,
            //menuId: this.queryParams.menuId,
            //parentNodeType: this.queryParams.parentNodeType,
            //parentSubTableName: this.queryParams.parentSubTableName,
            ids: this.ids
          }).then(response => {
            if (response.code == '200') {
              this.getlistPost();
              this.$modal.msgSuccess("删除成功");
            }
          })
        }).catch(() => { });
      } else {
        this.$message({ message: '请选择要删除的数据哦', type: 'warning' })
      }
    },

    //接收
    handleJieshouTap() {
      for (var i in this.selection) {
        if (this.selection[i].FOURCHECK != null || this.selection[i].FOURCHECK != undefined) {
          if (this.selection[i].FOURCHECK == 0) {
            this.$message({ message: '您有四性检测未通过的数据哦', type: 'warning' })
            return
          }
        }

      }

      if (this.ids != undefined && !this.multiple) {
        this.$modal.confirm('是否确认接收所选数据数据项？').then(function () {
        }).then(() => {
          jieshouSzhDa({
            categoryId: this.queryParams.categoryId,
            ids: this.ids
          }).then(res => {
            console.log(res)
            if (res.data.count > 0) {
              this.$message({ message: '有' + res.data.count + '未接收，请检查四性检测是否通过', type: 'warning' })
              this.getlistPost();
            } else {
              this.getlistPost();
              this.$modal.msgSuccess("接收成功");
              setTimeout(res => {
                // this.$router.push({ path: "/archive/fileCollection/fileOrganization" })
              }, 1000)
            }


          })

        }).catch(() => { });
      } else {
        this.$message({ message: '请选择要接收的数据哦', type: 'warning' })
      }
    },



    //双击列表进入详情页面
    celldblclick(row) {
      var label = "";
      var level = "";
      if (getLastIndexOf(this.queryParams.sub_table_name) == "F") {  //F 件
        level = 0
        label = row.TITLE;
      } else if (getLastIndexOf(this.queryParams.sub_table_name) == "V") { //卷
        level = 1
        label = row.TITLE;
      } else { //项目
        level = 3
        label = row.XMMC;

      }
      this.celldbData = {
        id: row.ID,
        categoryId: this.queryParams.categoryId,
        menuId: this.queryParams.menuId,
        sub_table_name: this.queryParams.sub_table_name,
        label: label,
        level: level,
        ifSub_table_name: this.queryParams.sub_table_name,
        isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
        tableHeaderList: this.tableHeaderList
      }
      // console.log(this.subStr,"+++++++++++++")
      this.$nextTick(() => {
        if (this.subStr == "F") {  //F 进入件详情
          this.jianDetailsOpen = true;
        } else { //进入卷详情 和项目详情
          this.juanDetailsOpen = true
        }
      })

    },
    //关闭详情页面
    detailsHandleClose() {
      this.jianDetailsOpen = false;
      this.juanDetailsOpen = false;
      this.projectJuanlistDeitOpen = false;
    },

    //排序
    sortChange(val) {
      // console.log(val, "ksdfjkl")
      this.queryParams.order = val;
      // console.log(this.queryParams, "+++")
      this.getlistPost();
    },

    //打印目录
    printTap() {
      this.printList = [];
      if (this.ids != undefined) {
        this.printOpen = true
        var idsData = this.ids.split(",")
        for (var i in this.tableData) {
          for (var j in idsData) {
            if (this.tableData[i].ID == idsData[j]) {
              this.printList.push(this.tableData[i])
            }
          }
        }
      } else {
        this.$message({ message: '请选择要打印的数据哦', type: 'warning' })
      }
    },

    print1Tap() {
      var data = [];
      this.printList = [];
      if (this.ids != undefined && !this.multiple) {
        // var idsData = this.ids.split(",")
        // for (var i in this.tableData) {
        //   for (var j in idsData) {
        //     if (this.tableData[i].ID == idsData[j]) {
        //       this.printList.push(this.tableData[i])
        //     }
        //   }
        // }
        // data = { data: this.printList };
        // geturl({
        //   categoryId: this.queryParams.categoryId,
        //   menuId: this.queryParams.menuId,
        //   type: getLastIndexOf(this.queryParams.sub_table_name),
        //   data: JSON.stringify(data),
        // }).then(res => {
        //   if (res.data.result == "fail") {
        //     this.$message({ message: res.data.msg, type: 'warning' })
        //   } else {
        //     // window.location.href=res.msg;
        //     console.log(res.data.url,"dklsfjkl")
        //     window.open(res.data.url);
        //   }
        //
        //
        // })
        getlistbytreenodeList(this.queryParams).then(response => {
          var printTableData = response.rows;
          this.getPrintList(printTableData, this.queryParams.sub_table_name)
        });
      } else {
        this.$message({ message: '请选择要打印的数据哦', type: 'warning' })
      }
    },
    //处理好的打印数据方法
    getPrintList(printTableData, sub_table_name) {
      var that = this;
      var data = [];
      var datalist = ['data']
      this.printList = [];
      var idsData = this.ids.split(",")
      for (var i in this.tableHeaderList) {
        if (this.tableHeaderList[i].SHOWTYPE == 5) {
          for (var j in printTableData) {
            // console.log(printTableData[j])
            for (var x in this.dictList[this.tableHeaderList[i].FIELD_NAME]) {
              if (printTableData[j][this.tableHeaderList[i].FIELD_NAME] == this.dictList[this.tableHeaderList[i].FIELD_NAME][x].dictValue) {
                printTableData[j][this.tableHeaderList[i].FIELD_NAME] = this.dictList[this.tableHeaderList[i].FIELD_NAME][x].dictLabel
              }
            }
          }
        }
      }
      var printList = [];
      for (var c in printTableData) {
        for (var k in idsData) {
          if (printTableData[c].ID == idsData[k]) {
            printList.push(printTableData[c])
          }
        }
      }
      data = [{ data: printList }];
      geturl({
        categoryId: this.queryParams.categoryId,
        menuId: this.queryParams.menuId,
        type: getLastIndexOf(sub_table_name),
        data: JSON.stringify(data),
        datalist: JSON.stringify(datalist)
      }).then(res => {
        if (res.data.result == "fail") {
          this.$message({ message: res.data.msg, type: 'warning' })
        } else {
          window.open(res.data.url);
        }
      })
    },

    // 排卷号/排件号
    rowNumber() {
      if (this.ids == undefined || this.ids.length == 0) {
        this.$message({ message: '请选择需要排档号的数据', type: 'warning' })
        return false
      }
      this.form = {
        categoryId: this.queryParams.categoryId,
        sub_table_name: this.queryParams.sub_table_name
      }
      this.form.ids = this.ids
      if (this.subStr == "F") {  //F 件
        this.form.type = 0
      } else if (this.subStr == "V") { //卷
        this.form.type = 1
      } else { //项目
        this.form.type = 3
      }
      pieceNumber1(this.form).then(response => {
        this.getlistPost()
        this.$modal.msgSuccess('排档号成功')
      })
    },
    // 清空卷/件号
    cleanUp() {
      if (this.ids == undefined || this.ids.length == 0) {
        this.$message({ message: '请选择需要清空档号的数据', type: 'warning' })
        return false
      }
      this.form = {
        categoryId: this.queryParams.categoryId,
        sub_table_name: this.queryParams.sub_table_name
      }
      this.form.ids = this.ids
      if (this.subStr == "F") {  //F 件
        this.form.type = 0
      } else if (this.subStr == "V") { //卷
        this.form.type = 1
      } else { //项目
        this.form.type = 3
      }
      clearNumber1(this.form).then(response => {
        this.getlistPost()
        this.$modal.msgSuccess('清空档号成功')
      })
    },
    // 手动排档号
    manualNumber() {
      if (this.ids == undefined || this.ids.length == 0) {
        this.$message({ message: '请选择要手动排档号数据哦', type: 'warning' })
        return false
      }
      if (this.single) {
        this.$message({ message: '请选择一条要手动排档号的数据哦', type: 'warning' })
        return false
      }
      this.form = {
        categoryId: this.queryParams.categoryId,
        sub_table_name: this.queryParams.sub_table_name
      }
      this.form.ids = this.ids
      if (this.subStr == "F") {  //F 件
        this.form.type = 0
      } else if (this.subStr == "V") { //卷
        this.form.type = 1
      } else { //项目
        this.form.type = 3
      }
      getLastZlx3(this.form).then(response => {
        this.number.title = response.data.fieldCaption
        this.number.open = true;
        this.number.info = response.data
      })
    },
    // 关闭手动排档号
    numberCancelTap() {
      this.number.open = false;
      this.getlistHeaderPost()
    },
    // 保存手动排档号
    submitNumberForm(form) {
      this.form = {
        categoryId: this.queryParams.categoryId,
        sub_table_name: this.queryParams.sub_table_name,
        ids: this.ids,
        ruleId: form.ruleId,
        buling: form.buling,
      }
      if (this.subStr == "F") {  //F 件
        this.form.type = 0
      } else if (this.subStr == "V") { //卷
        this.form.type = 1
      } else { //项目
        this.form.type = 3
      }
      var key = form.key;
      var value = form.value;
      // 动态追加键值对
      this.form[key] = value;
      insertPieceNumber(this.form).then(response => {
        this.getlistPost()
        this.number.open = false;
        this.$modal.msgSuccess('手动排档号成功')
      })
    },
    // 案卡信息
    handleInfoDetailTap() {
      if (this.ids == undefined || this.ids.length == 0) {
        this.$message({ message: '请选择要查看案卡信息的数据哦', type: 'warning' })
        return false
      }
      if (this.single) {
        this.$message({ message: '请选择一条要查看案卡信息的数据哦', type: 'warning' })
        return false
      }
      this.info.open = true
      this.$nextTick(() => {
        this.$refs.infoRef.init(this.ids)
      })
    },
    // 关闭案卡信息弹窗
    infoCancelTap() {
      this.info.open = false
    }
  }
}
</script>
